package com.neutech.code.user;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class BaseDao {


        private static Connection conn;
        public static final String DRIVER="com.mysql.cj.jdbc.Driver";
        public static final String URL="jdbc:mysql://localhost:3306/users";
        public static final String USER="root";
        public static final String PASSWORD = "123456";
        static{
            try {
                Class.forName(DRIVER);
                conn = DriverManager.getConnection(URL,USER,PASSWORD);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        public BaseDao(){}
        public static Connection getConn(){
            return conn;
        }

//        public static void close(Statement  statement){
//            if(statement!=null){
//                try {
//                    statement.close();
//                } catch (SQLException e) {
//                    throw new RuntimeException(e);
//                }
//            }
//        }
        public static void close(ResultSet resultSet,Statement statement){
            try{
                if(resultSet!=null){
                    resultSet.close();
                }
                if(statement!=null){
                    statement.close();
                }


            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
//        public static void close(){}
}
